<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Common {

	static function pr($var) {
		echo "<pre style=\"font-size: 11px; border: 1px solid red; padding:10px;\">\n";
		if($var) {
			print_r($var);
		} else {
			var_dump($var);
		}
		echo "</pre>\n";
	}

	static function underscore($word) {
		return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/','_', preg_replace('/([a-zd])([A-Z])/','\\1_\\2', preg_replace('/([A-Z]+)([A-Z][a-z])/','\\1_\\2', $word))));
	}

	static function coalesce($values) {
		foreach($values as $value) {
			if($value) {
				return $value;
			}
		}
		return "";
	}

	static function now() {
		return date("Y-m-d H:i:s");
	}

	static function prepare_str($str) {
		$str = str_replace("&nbsp;", " ", $str);
		return preg_replace('/\s\s+/', ' ', trim($str));
	}

	static function american2decimal($odd) {
		if($odd <=-100) {
			return (1 - (100/$odd));
		} else {
			return (1 + ($odd/100));
		}
	}
	
}
?>